package edu.pku.sei.transformation.editor.controller.commands.node;

import org.eclipse.gef.commands.Command;


public class NestedCommand extends Command {
	protected Command modelCmd;
	protected boolean modelCmdNecessary = true;
	
	public boolean isModelCmdNecessary() {
		return modelCmdNecessary;
	}

	public void setModelCmdNecessary(boolean modelCmdNecessary) {
		this.modelCmdNecessary = modelCmdNecessary;
	}

	public NestedCommand() {
		super();
	}
	
	public NestedCommand(String label) {
		super(label);
	}
	public Command getModelCmd() {
		return modelCmd;
	}

	public void setModelCmd(Command modelCmd) {
		this.modelCmd = modelCmd;
	}
	
	@Override
	public boolean canExecute() {
		if (modelCmdNecessary) {
			if (modelCmd != null)
				return modelCmd.canExecute();
			else
				return false;
		} else {
			return true;
		}
	}
	
	@Override
	public boolean canUndo() {
		if (modelCmdNecessary) {
			if (modelCmd != null)
				return modelCmd.canUndo();
			else
				return false;
		} else {
			return true;
		}
	}
}
